﻿var HtmlEditor=parent.fastCSharp.Object[fastCSharp.Query.id],ThisInputId='BorderColor';
var ClickColor=function(_,Color)
	{
	fastCSharp.$Id(ThisInputId).Value(Color);
	};
var MoveColor=function()
	{
	fastCSharp.$Id(ThisInputId).Focus();
	};
var FormatMinValue=function(Value,MinValue)
	{
	return Math.max(parseInt(0+Value,10),MinValue);
	};
var FormatWidth=function(Value)
	{
	return Math.min(parseInt(0+Value,10),fastCSharp.$Id('SelectWidth').Get('selectedIndex')==0?100:800);
	};
var FormatColor=function(Value)
	{
	return parseInt(0+Value,16).toString(16).PadLeft(6,'0');
	};
var Show=function()
	{
	var Value=Form.GetValue();
	var Html=["<table border='"+Value.Border+"' cellspacing='"+Value.CellSpace+"' cellpadding='"+Value.CellMargin+"'"+(fastCSharp.$Id('IsWidth').Get('checked')?(" width='"+Value.Width+(Value.SelectWidth==0?"%":"px")+"'"):'')+" bordercolor='"+Value.BorderColor+"' bgcolor='"+Value.BgColor+"'"+(Value.Align?(" align='"+Value.Align+"'"):'')+">"];
	for(var TD=[],Index=parseInt(Value.Col);Index>0;Index--)	TD.push('<td>&nbsp;</td>');
	TD=TD.join('');
	for(var Index=parseInt(Value.Row);Index>0;Index--)	Html.push('<tr>'+TD+'</tr>');
	Html.push('</table>');
	HtmlEditor.PasteHtml(Html.join(''),0);
	HtmlEditor.ShowOver();
	};
var LoadForm=function()
	{
	fastCSharp.NewObject('Color512_64',{Id:'ColorSpan',CurrentColor:'ThisColor',OnClick:ClickColor,OnMove:MoveColor}).Start();
	var Elements={
		Row:	{
			MaxLength:4,
			OnFormat:function(Form,Value){return FormatMinValue(Value,1);}
			},
		Col:	{
			MaxLength:4,
			OnFormat:function(Form,Value){return FormatMinValue(Value,1);}
			},
		Border:	{
			MaxLength:4,
			OnFormat:function(Form,Value){return FormatMinValue(Value,0);}
			},
		CellSpace:
			{
			MaxLength:4,
			OnFormat:function(Form,Value){return FormatMinValue(Value,0);}
			},
		CellMargin:
			{
			MaxLength:4,
			OnFormat:function(Form,Value){return FormatMinValue(Value,0);}
			},
		Width:	{
			MaxLength:3,
			OnFormat:function(Form,Value){return FormatWidth(Value);}
			},
		BorderColor:
			{
			MaxLength:6,
			OnFormat:function(Form,Value){return FormatColor(Value);}
			},
		BgColor:{
			MaxLength:6,
			OnFormat:function(Form,Value){return FormatColor(Value);}
			}
		};
	var Value={Row:2,Col:2,Align:0,Border:1,CellSpace:0,CellMargin:0,Width:100,SelectWidth:0,BorderColor:'000000',BgColor:'ffffff'};
	window.Form=fastCSharp.NewObject('Form',{FormId:'Form',DefaultValue:Value,Elements:Elements,Buttons:[{Id:'ReturnButton',OnClick:Show}]});
	Form.Start();

	fastCSharp.$Id('BorderColor').Element().onfocus=fastCSharp.$Id('BgColor').Element().onfocus=function()
		{
		ThisInputId=this.id;
		this.select();
		};
	fastCSharp.$Id('SelectWidth').Element().onchange=function()
		{
		fastCSharp.$Id('Width').Focus().Blur();
		};
	fastCSharp.$Id('IsWidth').Element().onclick=function()
		{
		fastCSharp.$Id('Width').Disabled(!this.checked);
		fastCSharp.$Id('SelectWidth').Disabled(!this.checked);
		};
	};
fastCSharp.OnModule(['htmlEditor'],LoadForm);
